package com.etc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.etc.dao.ArticleMapper;
import com.etc.entity.Article;
import com.etc.entity.ArticleExample;
import com.etc.service.ArticleService;
import com.etc.tools.ResponseData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleMapper articleMapper;

	@Override
	public ResponseData<Article> getArticleByLike(String keywords, Integer page, Integer limit) {
		PageHelper.startPage(page, limit);
		ArticleExample example = new ArticleExample();
		// ?
		example.createCriteria().andTitleLike("%" + keywords + "%");
		// selectByExample 一个新的方法
		List<Article> list = articleMapper.selectByExample(example);
		// 用PageInfo对结果进行包装
		PageInfo pageInfo = new PageInfo(list);
		ResponseData<Article> rd = new ResponseData<Article>(0, "success", pageInfo.getTotal(), list);
		return rd;
	}

}
